let rec power x = function
  | 0 -> 1
  | n -> x * power x (n-1) ;;

let rec application p x = match p with
   [] -> 0
  |(a,b)::l -> a * power x b + application l x ;;

let rec add p1 p2 = match (p1,p2) with
   (p,[])| ([],p) -> p
  |((a1,b1)::p1) , ((a2,b2)::p2) ->
    
     if b1=b2 then
       (a1+a2,b1)::(add p1 p2)
     else
         if b1>b2 then
           (a2,b2)::((add ((a1,b1)::p1) p2))
         else
	   (a1,b1)::((add p1 ((a2,b2)::p2))) ;;
            
let rec soustract p1 p2 = match (p1,p2) with
   (p,[])| ([],p) -> p
  |((a1,b1)::p1) , ((a2,b2)::p2) ->
    
     if b1=b2 then
       (a1-a2,b1)::(soustract p1 p2)
     else
         if b1>b2 then
          (a2, b2)::((soustract  ((a1,b1)::p1) p2))
         else
	   (a1,b1)::((soustract p1 ((  a2,b2)::p2)));;
          

soustract [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)] ;;
